/*
 * Property.cpp
 *
 *  Created on: Mar 24, 2011
 *      Author: kimi
 */
#include "Property.h"

/// Property Inner class Methods
Property::Property() {
	this->valid = false;
}

Property::Property(string key, string value) {
	this->key = key;
	this->value = value;
	this->valid = true;

	if (key.empty())
		valid = false;
}

Property::Property(string encoded) {
	size_t found;

	found = encoded.find("=");

	if (found == string::npos) {
		// cannot find delimiter, invalid property
		this->valid = false;

		cout << "[ERROR] invalid encoded property :: " << encoded << endl;

	} else {
		this->key = encoded.substr(0, found);
		this->value = encoded.substr(found + 1);
		this->valid = true;
	}

}

string Property::toString() {
	string encoded = this->key + "=" + this->value;
	return encoded;
}

bool Property::isInvalid() {
	return !this->valid;
}

Property & Property::operator=(const Property &prop) {
	if (this == &prop)
		return *this;

	this->key = prop.key;
	this->value = prop.value;
	this->valid = prop.valid;

	return *this;
}

string Property::getValue() {
	return this->value;
}
void Property::setValue(string value) {
	this->value = value;
}

string Property::getKey() {
	return this->key;
}

void Property::invalidate() {
	this->valid = false;
}

/*
Property::~Property() {

}
*/
